#! /usr/bin/env python
#coding=utf-8

from os import file, path

class Config():
	# config file
	__config__ = "";
    __config_handler__ = "";
	__service_dict__ = {};
    __default_service__ = "";

	def __init__(self, config):
		"""Init config environment"""
        self.__config__ = config;
		pass

	def config_open(self):
		"""Open config file for r/w"""
        self.__config_handler__ = open(self.__config__,"rw")
		pass

	def parse_service_list(self):
		"""Parse service list from config file"""
        for service in self.__config_handler__.readlines():
            item = service.split(" = ");
            __service_dict__[item[0]] = item[1];

		return __service_dict__;

	def get_default_service(self):
        """Get default service provider"""
        return self.__default_service__ ;

	def set_default_service(self):
        """Set default service provider"""
        self.__default_service__  = self.__service_dict__[0];
        pass

    def get_url_by_service_name(self, name):
        """Get service url by service name"""
        return self.__service_dict__[name];

	def store_new_service(self):
		"""Append new user customized service into config file"""
		pass

	def config_close(self):
		"""Close config file"""
        self.__config_handler__.close();
		pass

if __name__ == "__main__":
	# create new session
    # test routine

